<style lang="scss" scoped>
@import '../../style/mixin-rem.scss';
.book-search-results {
  padding: rem(20px) rem(40px) 0 rem(40px);
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: rem(18px);
  }
  .header_title {
    color: #42464e;
  }
  .icon-lajitong {
    color: #bbb;
    font-size: rem(16px);
  }
  .content {
    padding-top: rem(22px);
    background-color: #fff;
  }
  .content_item {
    font-size: rem(18px);
    color: #bbb;
    width: auto;
    padding-bottom: rem(20px);
  }
}
</style>

<template>
  <div class="book-search-results">
    <div class="header">
      <div class="header_title">搜索结果</div>
      <div class="btn_delete">
        <div class="iconfont icon-lajitong" @click="clearSearchResults"></div>
      </div>
    </div>
    <div class="content">
      <div class="content_item" v-for="(item, index) of searchResults" :key="item.id" @click="toDetailsPage(index)">
        {{item.title}}/{{item.author}}
      </div>
      <div class="content_item" v-show="searchResults === null">
        想要好书？？试试搜索一下吧~~
      </div>
      <div class="content_item" v-show="searchResults && searchResults.length === 0">
        搜索结果为空？试试换个词吧~~
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'BookSearchResults',
  computed: {
    searchResults () {
      return this.$store.state.bookSearch.searchResults
    }
  },
  methods: {
    clearSearchResults () {
      this.$store.commit('bookSearch/clearSearchResults')
    },
    toDetailsPage (index) {
      // console.log(this.searchResults[index].id)
      let infoId = `info-${this.searchResults[index].id}`
      this.$router.push({ name: 'bookDetails', params: { id: infoId } })
    }
  }
}
</script>
